#include <iostream>
#include <tbb/task_scheduler_init.h>

#include "ArgsParser.h"
#include "MultithreadTcpServer.h"
#include "TcpServer.h"
#include "SimpleTcpServer.h"

using namespace boost::asio;
using namespace std;
using namespace tbb;


int main(int argc, const char *argv[])
{
	cout.precision(3);

	try
	{
		ArgsParser argsParser(argc, argv);
		task_scheduler_init init;

		switch (argsParser.getServerType())
		{
		case ArgsParser::Multithread: {
			MultithreadTcpServer server(argsParser.getServerThreadCount(), argsParser.getPort());
			server.Run(); }
			break;

		case ArgsParser::SingleDispatcher: {
			TcpServer server(argsParser.getPort(), argsParser.getShowStat());
			server.Run(); }
			break;

		case ArgsParser::Simple: {
			SimpleTcpServer server(argsParser.getPort());
			server.Run(argsParser.getShowStat()); }
		    break;
		}
	}
	catch (exception &e)
	{
		cerr << e.what() << endl;
	}
	catch (...)
	{
		cerr << "Unknown exception" << endl;
	}

	return 0;
}